<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>菜鸟教程 React 实例</title>
    <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
    <script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    <script type="text/babel">
      var LikeButton = React.createClass({
        getInitialState: function() {
          return {redorblue:this.props.redorblue};
        },
        handleClick: function(event) {
          this.setState({redorblue:this.state.redorblue === 'red' ? 'blue' : 'red'});
        },
        render: function() {
          var color = this.state.redorblue;
          var style = {
            color:color
          }
          return (
          <div>
            <h3 style={style}>我是一个组件</h3>
            <p onClick={this.handleClick}>点我切换颜色</p>
          </div>
          )
        }
      });

      ReactDOM.render(
        <LikeButton redorblue="blue"/>,
        document.getElementById('example')
      );
    </script>
  </body>
</html>